package com.yzt.p_base.utils;

import android.os.Looper;

import androidx.annotation.NonNull;

/**
 * author : bob
 * date   : 2022/11/30
 * desc   :
 */
interface ITask {

    /**
     * post 到主线程，可以未post创建单独的Handler
     * @param keyAble key
     * @param task runnable task
     * @param delayMills delay
     * @param high 是否高优先级
     */
    void postMainTask(ThreadCenter.HandlerKeyable keyAble, Runnable task, long delayMills, boolean high);

    /**
     * post 到子线程，如果无threadName，那么就放入到线程池中执行
     * @param task  task
     * @param delayMills delay
     * @param highPriority priority
     * @param threadName threadName
     * @param threadPriority threadPriority
     */
    void postLogicTask(final Runnable task,
                       long delayMills,
                       boolean highPriority,
                       String threadName,
                       int threadPriority);

    /**
     * 清理掉Ui线程中对应keyAble的map中对应Handler中的任务
     * @param keyAble keyAble
     */
    void clearKeyAbleAllUiRunnable(@NonNull ThreadCenter.HandlerKeyable keyAble);

    /**
     * 清理掉Ui线程中对应keyAble的map中对应Handler中的任务
     * @see #clearKeyAbleAllUiRunnable(HandlerKeyable)
     * @param keyAble key
     */
    @Deprecated
    void clear(ThreadCenter.HandlerKeyable keyAble);

    /**
     * 移除UI task
     * @param label label
     * @param task task
     */
    void removeUITask(ThreadCenter.HandlerKeyable label, Runnable task);

    /**
     * 移除子线程，或者线程池中的task
     * @param task  task
     * @param threadName thread name
     */
    void removeLogicTask(Runnable task, String threadName);

    /**
     * idle 检查时，该信号会关闭线程池
     */
    void shutdown();

    /**
     * 判断当前是否设置了shutdown
     * @return isShutdown
     */
    boolean isShutdown();

    /**
     * 获取对应HandlerThread Looper，方便进行单元测试
     * @param threadName 线程名称
     * @return looper
     */
    Looper getHandlerThreadLooper(String threadName);
}

